package com.alks.function.controller;

import com.alks.common.aop.ApiRestController;
import com.alks.common.aop.WebLogger;
import com.alks.common.utils.UserInfoUtil;
import com.alks.entity.data.entity.PcStitchWorkerRep;
import com.alks.entity.data.entity.PcStitchWorkerReq;
import com.alks.entity.data.response.ResponseInfo;
import com.alks.function.data.request.sys.SdUserAddRequest;
import com.alks.function.data.request.sys.SdUserRequest;
import com.alks.function.data.request.sys.SdUserUpdateRequest;
import com.alks.function.mapper.SdPositionMapper;
import com.alks.function.service.SdUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@ApiRestController("/sdUser")
@Api(tags = {"系统管理-用户资料","开发-员工条码建档"})
@Slf4j
public class SdUserController {

    @Autowired
    private SdUserService sdUserService;

    @ApiOperation(tags = "系统管理-用户资料", value = "查询列表")
    @PostMapping("/getUser")
    @WebLogger
    public ResponseInfo getUserList(@RequestBody SdUserRequest request) {
        return sdUserService.getUser(request);
    }

    @Autowired
    private SdPositionMapper positionMapper;

    @ApiOperation(tags = "系统管理-用户资料", value = "查询职务")
    @GetMapping("/getPosition")
    @WebLogger
    public ResponseInfo getPosition() {
        String companyId = UserInfoUtil.getUserInfo().getCompanyId();
        return ResponseInfo.ok(positionMapper.getPosition(companyId));
    }

    @ApiOperation(tags = "系统管理-用户资料", value = "查询派工部门")
    @GetMapping("/getPcCuttingDispatchDept")
    @WebLogger
    public ResponseInfo getPcCuttingDispatchDept() {
        return ResponseInfo.ok(positionMapper.getPcCuttingDispatchDept());
    }

    @ApiOperation(tags = "系统管理-用户资料", value = "修改用户")
    @PutMapping("/updateUser")
    @WebLogger
    public ResponseInfo updateUser(@RequestBody SdUserUpdateRequest request) {
        return sdUserService.updateUser(request);
    }

    @ApiOperation(tags = "系统管理-用户资料", value = "添加用户")
    @PostMapping("/addUser")
    @WebLogger
    public ResponseInfo addUser(@RequestBody SdUserAddRequest request) {
        return sdUserService.addUser(request);
    }

    @ApiOperation(tags = "系统管理-用户资料", value = "重置密码")
    @PutMapping("/reset")
    @WebLogger
    public ResponseInfo reset(@RequestParam String userId) {
        return sdUserService.updatePwd(userId);
    }

    @ApiOperation(tags = "系统管理-用户资料", value = "修改密码")
    @PostMapping("/updatePassword")
    @WebLogger
    public ResponseInfo updatePassword(@RequestParam String userId,@RequestParam String oldPassword, @RequestParam String newPassword) {
         return sdUserService.updatePassword(userId,oldPassword,newPassword);
    }

    @ApiOperation(tags = "系统管理-用户资料", value = "删除")
    @PostMapping("/delUser")
    @WebLogger
    public ResponseInfo delUser(@RequestParam String userId) {
        return sdUserService.delUser(userId);
    }

    @ApiOperation(tags = "开发-员工条码建档", value = "员工资料查询")
    @PostMapping("/stitch/workerList")
    @WebLogger
    public ResponseInfo workerList(@RequestBody PcStitchWorkerReq req){
        return sdUserService.workerList(req);
    }

    @ApiOperation(tags = "开发-员工条码建档", value = "员工条码")
    @GetMapping("/stitch/workName")
    @WebLogger
    public ResponseInfo workName(@RequestParam String workId){
        return sdUserService.workName(workId);
    }

    @ApiOperation(tags = "开发-员工条码建档", value = "新增")
    @PutMapping("/stitch/insertWorker")
    @WebLogger
    public ResponseInfo insertWorker(@RequestBody PcStitchWorkerRep req){
        return sdUserService.insertWorker(req);
    }

    @PostMapping("/stitch/deleteStitchWorkersByIds")
    @WebLogger
    @ApiOperation(tags = "开发-员工条码建档", value = "删除打勾员工")
    public ResponseInfo deleteStitchWorkersByIds(@RequestBody List<String> ids){
        return sdUserService.deleteStitchWorkersByIds(ids);
    }


    @WebLogger
    @PostMapping("/stitch/updateStitchWorker")
    @ApiOperation(tags = "开发-员工条码建档", value = "调整组别")
    public ResponseInfo updateStitchWorker(@RequestBody List<String> ids, @RequestParam @ApiParam(required  = true,
    value = "针车组别",name = "line") String line){
        return sdUserService.updateStitchWorker(ids,line);
    }
}
